﻿using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DwarfScanner
{
    public partial class DwarfScannerMainForm : Form
    {
        private DwarfScanner scanner;

        public DwarfScannerMainForm()
        {
            InitializeComponent();

            scanner = new DwarfScanner();
        }

        private void ScanFilePrintResults(string filePath)
        {
            rtbResults.Clear();

            scanner.SetText(File.ReadAllText(filePath));
            Token t;
            do
            {
                t = scanner.GetNextToken();
                rtbResults.Text += t + "\n";
            } while (t.Type != TokenType.EOF);
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Multiselect = false;
            ofd.CheckPathExists = true;
            ofd.CheckFileExists = true;
            ofd.AddExtension = true;
            ofd.Filter = "Dwarf files(.dwarf)|*.dwarf|Simple text files(.txt)|*.txt|All files|(*.*)";

            if (ofd.ShowDialog(this) == DialogResult.OK)
            {
                ScanFilePrintResults(ofd.FileName);
            }
        }
    }
}
